use crate::api::prelude::*;
use axum::Extension;
use axum::extract::State;
use carpet::base::error::BadRequest;
use demo_api::api::prelude::*;
use demo_api::api::user::add_user::*;

#[derive(Handler)]
pub struct HandlerImpl {
    pub db: State<String>,
    pub ex: Extension<String>,
}

#[impl_handler(HandleDef_)]
impl HandlerImpl {
    pub async fn _handle(
        self,
        _path_data: Query<RequestData>,
        _json_data: Json<RequestData>,
    ) -> Result<ResponseData, Error> {
        Ok(ResponseData {
            sex: 2,
            message: String::from("abc"),
        })
    }
}

#[derive(Handler)]
pub struct PcImpl {
    pub db: State<String>,
}

#[impl_handler(PcDef_)]
impl PcImpl {
    pub async fn pc(
        self,
        _path_data: Path<RequestData>,
        _json_data: Json<RequestData>,
    ) -> Result<ResponseData, Error> {
        Ok(ResponseData {
            sex: 23,
            message: String::from("abc"),
        })
    }
}

#[impl_handler(MobileDef_)]
impl PcImpl {
    pub async fn mobile(self, _json_data: Json<RequestData>) -> Result<ResponseData, Error> {
        Err(BadRequest::from(String::from("请求错误")).into())
    }
}
